package com.huidian.resource.server.controller;

import com.huidian.resource.client.StudentFeign;
import com.huidian.resource.client.dto.StudentDto;
import com.huidian.resource.server.entity.Student;
import com.huidian.resource.server.service.IStudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author super on 2021-04-03 11:18:17
 * Copyright (c) huidiancloud
 */
@RestController
@Slf4j
public class StudentCtrl implements StudentFeign {

	@Resource
    private IStudentService studentService;

    @Override
    public List<StudentDto> selectList(@RequestBody StudentDto studentDto) {
        Student student = new Student();
        BeanUtils.copyProperties(studentDto,student);
        List<Student> studentList = studentService.selectList(student);
        List<StudentDto> studentDtoList = new ArrayList<>(studentList.size());
        StudentDto dto;
        for (Student m: studentList) {
            dto = new StudentDto();
            BeanUtils.copyProperties(m,dto);
            studentDtoList.add(dto);
        }
        return studentDtoList;
    }


    @Override
    public StudentDto selectById(@RequestParam("stdId") Long stdId) {
        Student student  = studentService.selectById(stdId);

        StudentDto studentDto = new StudentDto();
        BeanUtils.copyProperties(student,studentDto);

        return studentDto;
    }

	
}
